<!DOCTYPE html><!--修改分类名称-->
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:replace="common/amazingHeader2::amazing_header('添加类别')">
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form">
            <div class="layui-form-item">
                <label for="categoryName" class="layui-form-label">
                    <span class="x-red">*</span>分类名

                </label>
                <div class="layui-input-inline">
                    <input type="text" id="categoryName" name="categoryName" required="" lay-verify="required"
                           autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="x-red">*</span>原名称
                </label>
                <div class="layui-input-inline" style="padding-top: 20px">
                    <span class="x-red" id="oldName"></span>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                </label>
                <a class="layui-btn" onclick="changeCateName()">
                    增加
                </a>
            </div>
        </form>
    </div>
</div>
</body>
<script>
    const id = window.location.href.split('?')[1].split('=')[1];
    $.ajax({
        type: 'GET',
        url: 'cate/cateName',
        data: {
            'id': id
        },
        success: function (result) {
            $('#oldName').text(result.msg);
        }
    });

    function changeCateName() {
        const name = $('#categoryName').val();
        if (name.length < 2 || name.length > 10) {
            layer.msg('长度在2-10之间', {time: 1000, icon: 5, shift: 6});
            return false;
        }
        $.ajax({
            type: 'GET',
            url: 'cate/changeName',
            data: {
                'name': name,
                'id': id
            }, success: function (result) {
                layer.msg('修改成功！', {time: 1000, icon: 6, shift: 6});
                setTimeout(xadmin.close, 1000);
                setTimeout(xadmin.father_reload,1000);
            }
        })
    }
</script>
</html>